﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ConjureBivouac2012.Sprites;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework;

namespace ConjureBivouac2012.Object
{
    public class AbstractShield : Entity
    {
        protected float angle;
        protected float startingAngle;

        protected float shieldMinValue = 5;
        protected float shieldDecreaseDelay = -1;
        protected float shieldDecreaseAmount = 0;
        private float lastShieldDecrease = 0;

        public override void Initialize()
        {
            base.Initialize();
        }

        public void SetStartingAngle(float startAngle)
        {
            this.startingAngle = startAngle;
        }

        public override void Update(GameTime time)
        {
            if (shieldDecreaseDelay > 0 && (time.TotalGameTime.TotalSeconds - lastShieldDecrease >= shieldDecreaseDelay))
            {
                float newSize = ShieldSize - shieldDecreaseAmount;
                if (newSize >= shieldMinValue)
                {
                    ShieldSize = newSize;
                }
                
                lastShieldDecrease = (float)time.TotalGameTime.TotalSeconds;
            }

            base.Update(time);
        }

        //Shield size in degrees
        public virtual float ShieldSize
        {
            get { return angle; }
            set
            {
                if (value < 0)
                {
                    angle = 0;
                }
                else if (value > 360)
                {
                    angle = 360;
                }
                else
                {
                    angle = value;
                }
            }
        }
        
        public virtual void Draw(SpriteBatch spriteBatch, Vector2 pos, float radius)
        {
            Primitive2D.DrawArc(spriteBatch, pos, radius, 90, startingAngle, angle, Color.White, 5);
            //base.Draw(spriteBatch);
        }

        public virtual bool IsHurt(Vector2 colliderPos)
        {
            return false;
        }

        public virtual bool isHurt(Entity entity)
        {
            return false;
        }
    }
}
